<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">

    <title>login</title>
    <link rel="stylesheet" href="/media/css/login.css">

    <style>
    body {
      background-image: url("/media/login/back0.jpg");

    }
  </style>
</head>

<body>
    <div class="content" >
        <div class="content-wrapper">
            <div class="nav">
                <div class="logo">
                    <img src="/media/login/logo1.png" alt="">
                </div>
                <div class="nav-item" id="nav-sigin-btn">
                    <img src="/media/login/sigin.png" alt="">
                    <span>Signin</span>
                    <div class="block"></div>
                </div>
                <div class="nav-item" id="nav-sigup-btn">
                    <img src="/media/login/signup.png" alt="">
                    <span>SignUp</span>
                    <div class="block"></div>
                </div>
            </div>
            <div class="center">
                <div class="sigin-img-wrapper">
                    <div class="img-tips">
                        <h1>Start Your Work</h1>
                        <h5>One Key adn there links</h5>
                    </div>
                </div>
                <div class="sigup-img-wrapper">
                    <div class="img-tips">
                        <h1>Start Your Work</h1>
                        <h5>One Key adn there links</h5>
                    </div>
                </div>
            </div>
            <div class="form">

                <div class="form-wrapper">
                    <div class="sigin common-style">
						<form action="{% url 'login'%}"  id="form2" method=POST>
						    {% csrf_token %}
                        <div class="title">
                            <span>Don't have an account?</span>
                            <span>Sign In.</span>
                        </div>
                        <div class="inputs-wrapper">

                            <!-- Sign In -->
                           <div class="container__form container--signin">
                               <form action="{% url 'login'%}" class="form" id="form2" method=POST novalidate>
                               {% csrf_token %}
                               <h2 class="form__title">Sign In</h2>
                                   <div class="inputs-item items-user">
                                        <span class="input-tips">phonenumber</span>
                                        <input type="text" placeholder="phoneNumber" class="inputs" name="userName" id="phonenumber_2"/>
                                   </div>
                                   <div class="inputs-item items-pwd">
                                       <span class="input-tips">Password</span>
                                       <input type="password" placeholder="Password" class="inputs" name="password" id="password_2"/>
                                   </div>
                               <a href="#" class="link"  style="color: red; font-weight: bold; text-decoration: underline;">Forgot your password?</a>
                               <button onclick="submitForm('form2')" class="sigin-btn">Sign In</button>
                         </form>
                        </div>

                        </div>
                        <div class="tips">
                            <span class="tips-txt">By clicking the Sign In Button,you therefore agre to the Privacy
                                Policy.</span>
                        </div>
						</form>
                    </div>

                    <div class="sigup common-style">
						<form action="{% url 'register'%}" id="form1" method=POST>
						    {% csrf_token %}
                        <div class="title animations">
                            <span>have an account?</span>
                            <span>Sign Up.</span>
                        </div>
                        <div class="inputs-wrapper">
                            <div class="inputs-item items-user animations">
                                <span class="input-tips">phonenumber</span>
                                 <input type="text" placeholder="phoneNumber" class="inputs" name="userName" id="phonenumber_1"/>
                            </div>
                            <div class="inputs-item items-email animations">
                                <span class="input-tips">E-mail</span>
                                <input type="email" placeholder="Email" class="inputs" name="email" id="email"/>
                            </div>
                            <div class="inputs-item items-pwd animations">
                                <span class="input-tips">Password</span>
                                <input type="password" placeholder="Password" class="inputs" name="password" id="password_1"/>
                            </div>

							<div id="testdiv" style="display: flex; align-items: center;">
							    <input name="code" type="text" class="input1" placeholder="Verification code" id="code" style="padding: 10px; border: 1px solid #ccc; border-radius: 5px; width: 200px;">
							    <button class="btn1" onclick="send_code()" style="margin-left: 10px; padding: 10px 20px; background-color: #007bff; color: #fff; border: none; border-radius: 5px;">Send</button>
							</div>
                            <button onclick="check_1('form1')"class="sigin-btn animations">SIGN UP</button>
                        </div>
                        </form>
                    </div>
					</form>
                </div>
            </div>
        </div>
    </div>
<script>
    const fistForm = document.getElementById("form1");
    const secondForm = document.getElementById("form2");
    const container = document.querySelector(".container");

     fistForm.addEventListener("submit", (e) => e.preventDefault());
    secondForm.addEventListener("submit", (e) => e.preventDefault());

    function submitForm(str) {
        document.getElementById(str).submit();
        console.log(str)
    }
</script>
</body>

<script>
	function sendCode() {
	        var form = document.getElementById('codeform');
	        var input = document.createElement('input');
	        var text = document.getElementById('phonenumber_1').value;
	        input.setAttribute('name', "userName");
	        input.setAttribute('value', text);
	        form.append(input);
	        form.submit();
	    }

    function send_code(){
    var email = document.getElementById("email").value;
    var a = Math.round(Math.random()*8999+1000);
    data = new FormData();
    data.append("email",email);
    data.append("code",a);

    var xhr = new XMLHttpRequest();
    xhr.withCredentials = true;
    xhr.open("POST", 'getcode/');
    xhr.send(data);
    }

    function submitForm(str) {
        document.getElementById(str).submit();
        console.log(str)
    }
	function check_1(str) {
	    var phonenumber = document.getElementById("phonenumber_1").value;
	    console.log(phonenumber);
	    var email = document.getElementById("email").value;
	    console.log(email);
	    var password = document.getElementById("password_1").value;
	    console.log(password);
	    var judge = 0;

	    //判断密码是否合适
	    if (password.length < 6) {
	        alert("密码长度必须大于6为位！请重新输入！");
	    } else {
	        var num_1 = 0
	        var num_2 = 0
	        for (var i = 0; i <= password.length; i++) {
	            if (password[i] >= 'a' && password[i] <= 'z') {
	                num_1++;
	            } else if (password[i] >= 'A' && password[i] <= 'Z') {
	                num_2++;
	            }
	        }
	        var num = num_1 + num_2;
	        if (num < 2) {
	            alert("密码必须包含至少两个字母！请重新输入！");
	        } else if (num_1 === 0 || num_2 === 0) {
	            alert("密码必须同时包含大小写字母！请重新输入！");
	        } else {
	            // alert("密码格式正确！");
	            judge++;
	        }
	    }

	    //判断用户名是否合适
	    if (phonenumber.length !== 11) {
	        alert("电话号码长度应为11位！请重新输入！");
	    } else if (phonenumber[0] === 0) {
	        alert("电话号码的第一位不为0！请重新输入！");
	    } else {
	        var num = 0;
	        for (var i = 0; i < phonenumber.length; i++) {
	            if (phonenumber[i] >= 0 && phonenumber[i] <= 9) {
	                num++;
	            }
	        }
	        if (num !== 11) {
	            alert("电话号码应由0~9的数字组成！请重新输入！");
	        } else {
	            // alert("用户名输入格式正确！");
	            judge++;
	        }
	    }

	    //判断邮箱格式是否正确
	    var num = 0;
	    for (var i = 0; i < email.length; i++) {
	        if (email[i] === '@') {
	            num++;
	        }
	    }
	    if (num === 0) {
	        alert("邮箱中应包含一个@符号！请重新输入！");
	    } else if (num >= 2) {
	        alert("邮箱中应只包含一个@符号！请重新输入！");
	    } else {
	        // alert("邮箱格式输入正确！");
	        judge++;
	    }

	    if (judge === 3) {
	        submitForm(str);
	    }
	}

    const siginBtn = document.getElementById('nav-sigin-btn');
    const sigupBtn = document.getElementById('nav-sigup-btn');
    const siginForm = document.querySelector('.sigin');
    const sigupForm = document.querySelector('.sigup');
    const siginImgWrapper = document.querySelector('.sigin-img-wrapper');
    const sigupImgWrapper = document.querySelector('.sigup-img-wrapper');
    const animations = document.querySelectorAll('.animations');
    const nav = document.querySelector('.nav');
    const form = document.querySelector('.form');
    const center = document.querySelector('.center');

    let flag = true;
    sigupBtn.onclick = function () {
        if (flag) {
            flag = false;
            siginForm.style.top = '140%';
            siginImgWrapper.style.transform = 'translateY(-100%)';
            sigupImgWrapper.style.transform = 'translateY(-100%)';
            nav.classList.add('nav-form-animation-bottom');
            form.classList.add('nav-form-animation-bottom');
            nav.classList.remove('nav-form-animation-top');
            form.classList.remove('nav-form-animation-top');
            setTimeout(function () {
                sigupForm.style.zIndex = '1';
                sigupForm.style.top = '50%';
                for (let i = 0; i < animations.length; i++) {
                    setTimeout(function () {
                        animations[i].style.transition = '1s';
                        animations[i].style.opacity = '1';
                        animations[i].style.transform = 'translate(0, 0)';
                        if (i == animations.length - 3) {
                            flag = true;
                        }
                    }, i * 250)
                }
            }, 500)
        }
    }

    siginBtn.onclick = function () {
        if (flag) {
            flag = false;
            siginForm.style.top = '50%';
            sigupForm.style.transition = '1s';
            sigupForm.style.top = '-100%';
            siginImgWrapper.style.transform = 'translateY(0%)';
            sigupImgWrapper.style.transform = 'translateY(0%)';
            nav.classList.remove('nav-form-animation-bottom');
            form.classList.remove('nav-form-animation-bottom');
            nav.classList.add('nav-form-animation-top');
            form.classList.add('nav-form-animation-top');
            flag = true
            setTimeout(function () {
                sigupForm.style.zIndex = '-1';
                for (let i = 0; i < animations.length; i++) {
                    animations[i].style.transition = '0';
                    animations[i].style.opacity = '0';
                    animations[i].style.transform = 'translate(-10%, 0)';
                }
                sigupForm.style.top = '-50%';
            }, 1000)
        }
    }
</script>
</html>
